

/*
    Copyright 2011,2012 Calum Stuart Cookson.

    This file is part of Bio Mongoose.

    Bio Mongoose is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Bio Mongoose is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Bio Mongoose.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "utility.h"

#include "city.hpp"

#include <fstream>
#include <iostream>

using namespace std;

utility::utility()
{
    //ctor
}

utility::~utility()
{
    //dtor
}

string utility::get_file(string fname)
{
	ifstream infile(fname.c_str());
	string data;
	char buf[1024*1024] = {0};

	while(data+=buf, infile.good())
		infile.get(buf, (1024*1024)-1);

	infile.close();
	return data;
}

vector<string> utility::split(string _str, string delims=" \t,")
{
    vector<string> ret;
    string::size_type pos1 = 0;
    string::size_type pos2;

    while( (pos2 = _str.find_first_of(delims, pos1)) != string::npos)
    {
        ret.push_back(_str.substr(pos1, pos2-pos1));
        pos1 = pos2+1;
    }
    ret.push_back(_str.substr(pos1));
    return ret;
}

string utility::get_disclaimer_text()
{
    return string()+"This program is free software: you can redistribute it and/or modify\r\n" +
    "it under the terms of the GNU General Public License as published by\r\n" +
    "the Free Software Foundation, either version 3 of the License, or\r\n"+
    "(at your option) any later version.\r\n\r\n" +

    "This program is distributed in the hope that it will be useful,\r\n" +
    "but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n" +
    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n" +
    "GNU General Public License for more details.\r\n\r\n" +
    "You should have received a copy of the GNU General Public License\r\n" +
    "along with this program.  If not, see <http://www.gnu.org/licenses/>\r\n";
}

std::string utility::generate_copyright_notice(std::string project_name, std::string description, std::string copyright_string)
{
    return project_name + "\r\n"
    + description + "\r\n"
    + copyright_string + "\r\n";
}

string utility::get_head(const string &sequence, string::size_type length)
{
    return sequence.substr(0,length);
}

string utility::get_tail(const string &sequence, string::size_type length=1)
{
    return sequence.substr(sequence.length()-length, length);
}

uint64 utility::hash_function(const std::string &str)
{
    //cerr << CityHash64(str.c_str(), str.length()) << endl;
    return CityHash64(str.c_str(), str.length());
}
